import service from './service'

enum projectStatus {
  open,
  closed,
  in_progress,
  completed,
}

export const getProjectListAPI = async (params: {
  page: number
  size: number
  keyword: string
  status: projectStatus
  category: string
}) => {
  return await service.get('/projects', {
    params,
  })
}

export const createProjectAPI = async (params: {
  title: string
  description: string
  requirements: string
  budget: number
  deadline: string // date 类型通常用字符串表示，比如 "2024-12-31"
  category: string
  tags: string[]
}) => {
  return await service.post('/projects', params)
}

export const getProjectDetailAPI = async (id: number) => {
  return await service.get(`/projects/${id}`)
}

export const refreshProjectAPI = async (
  id: number,
  params: {
    title: string
    description: string
    requirements: string
    budget: number
    deadline: string
    category: string
    tags: string[]
  },
) => {
  return await service.put(`/projects/${id}`, params)
}

export const deleteProjectAPI = async (id: number) => {
  return await service.delete(`/projects/${id}`)
}

export const getMyProjectAPI = async () => {
  return await service.get('/projects/my')
}

export const applyProjectAPI = async (
  id: number,
  params: {
    cover_letter: string
    resume: string
    portfolio: string
  },
) => {
  return await service.post(`/projects/${id}/applications`, params)
}
